package com.lwm.base;

/**
 * @author liweimin
 * @date 2020/9/23 9:19
 * @description label: 就是标签  要终止的位置
 *
 * break label ：终止结束到标签 结束语句
 *
 * continue label: 终止本次循环 跳到标签位置进行接下来的循环
 */
public class LabelTest {
    public static void main(String[] args) {
        String strSearch = "This is the string in which you have to search for a substring.";
        String substring = "substring";
        boolean found = false;
        int max = strSearch.length() - substring.length();
        testlbl:
        for (int i = 0; i <= max; i++) {
            int length = substring.length();
            int j = i;
            int k = 0;
            while (length-- != 0) {
                if(strSearch.charAt(j++) != substring.charAt(k++)){
                    continue testlbl;
                }
            }
            found = true;
            break testlbl;
        }
        if (found) {
            System.out.println("发现子字符串。");
        }
        else {
            System.out.println("字符串中没有发现子字符串。");
        }
    }
}
